/*
	设将n(n>1)个整数数组存放到一维数组R中。设计一个在时间空间两个方面都尽可能高效的算法。将R中保存的序列循环左移p(0<p<n)
	使用两个顺序表实现，空间复杂度为n 时间复杂度为n
	使用连续三次反转实现空间复杂度为1 时间复杂度为n
*/

#include<stdio.h>
#include<malloc.h>
#include"..\Sequence_List\zyf_SqList.h"

void circuitList1(SqList *L,SqList *tmp,int p)
{
	int j = 0;
	if (p >= L -> length)
		printf("移动的长度必须小于顺序表的长度\n");

	//struct sqlist tmp;

	for (int i = 0 ; i < p ; i++)
	{
		tmp -> elem_array[i] = L -> elem_array[i];
	}

	for (int i = p;i < L -> length;i++)
	{
		L -> elem_array[i - p] = L -> elem_array[i];
	}


	for (int i = L -> length - p ;i <= L -> length ; i++)
	{
		L -> elem_array[i] = tmp -> elem_array[j++];
	}

}



int main(void)
{
	struct sqlist La;
	struct sqlist Lb;

	printf("初始化状态为%d\n",Init_SqList(&La));
	printf("初始化状态为%d\n\n",Init_SqList(&Lb));

	printf("添加元素状态%d\n",Insert_SqList(&La,1,4 ));
	printf("添加元素状态%d\n",Insert_SqList(&La,2,5 ));
	printf("添加元素状态%d\n",Insert_SqList(&La,3,8 ));
	printf("添加元素状态%d\n",Insert_SqList(&La,4,9 ));
	printf("添加元素状态%d\n",Insert_SqList(&La,5,10));
	printf("添加元素状态%d\n",Insert_SqList(&La,6,11));

	circuitList(&La,&Lb,2);

	for (int i = 0; i < La.length; i++)
	{
		printf("第%d个值为：%d\n",i+1,La.elem_array[i]); 
	}
}